import time
import XenAPI

def get_xapi_session(url):
    session = XenAPI.Session(url)
    session.xenapi.login_with_password('root','5531248yu')
    return session

def get_vm_list():
    url = "https://10.20.0.1:443"
    session=get_xapi_session(url)
    vms = session.xenapi.VM.get_all()
    vm_list=[]
    for vm in vms:
        record = session.xenapi.VM.get_record(vm)
        if not(record["is_a_template"]) and not(record["is_control_domain"] and record["power_state"] == "Running"):
            name = record["name_label"]
            vm_list.append(name)
    print len(vm_list)

get_vm_list()